package com.kafka.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import java.util.concurrent.CompletableFuture;

/**
 * 空操作的Kafka生产者服务实现
 * 当kafka.enabled=false时使用
 */
@Service
@ConditionalOnProperty(name = "kafka.enabled", havingValue = "false")
@Primary
public class NoOpKafkaProducerService implements KafkaProducerService {
    private static final Logger logger = LoggerFactory.getLogger(NoOpKafkaProducerService.class);

    @Override
    public CompletableFuture<Void> sendMessageAsync(String topic, String message) {
        logger.debug("Kafka is disabled - Skipping async message to topic: {}", topic);
        return CompletableFuture.completedFuture(null);
    }

    @Override
    public boolean sendMessageSync(String topic, String message) {
        logger.debug("Kafka is disabled - Skipping sync message to topic: {}", topic);
        return true; // 假设发送成功
    }

    @Override
    public void sendMessageWithKey(String topic, String key, String message) {
        logger.debug("Kafka is disabled - Skipping keyed message to topic: {}, key: {}", topic, key);
    }
}